package com.dabao.util;

import java.math.BigDecimal;

/**
 * Created by card on 16/2/4.
 */
public class AmountUtils {

    /**
     * 将单位为元的金钱转化为单位为分的金额
     * 1.00->100
     * @param amount
     * @return
     */
    public static int toIntValue(String amount) {
        return new BigDecimal(amount).multiply(new BigDecimal(100)).intValue();
    }

    /**
     * 将单位为分的金钱转化为单位为元的金额
     * 100->1.00
     * @param amount
     * @return
     */
    public static String toStringValue(int amount) {
        return new BigDecimal(amount)
                .divide(new BigDecimal(100))
                .setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }
}
